//package com.example.adminservice.config;
//
//import com.example.adminservice.pojo.Admin;
//import com.example.adminservice.service.AdminService;
//import org.springframework.beans.factory.annotation.Autowired;
//import sun.net.www.protocol.http.AuthenticationInfo;
//
//import javax.security.auth.Subject;
//
///**
// * @author 鱼凫
// * @version 1.0
// * Create by 2023/3/5 15:27
// */
//public class  AdminRealm extends AuthorizingRealm {
//
//
//    @Autowired
//    AdminService adminService;
//    //    授权
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
//        System.out.println("执行授权");
//        //SimpleAuthorizationInfo
//        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
////        info.addStringPermission("admin:add");
//        //拿到当前登录用户
//        Subject subject = SecurityUtils.getSubject();
//        Admin principal = (Admin) subject.getPrincipal();
////        获取用户权限
//        info.addStringPermission(principal.getWait1());
//        return info;
//    }
//
//    //    登录
//    @Override
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//        System.out.println("执行认证");
//        UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
//        //连接数据库
//        Admin admin = adminService.getById(token.getUsername());
//        if (admin==null){
//            return null;
//        }
//        return new SimpleAuthenticationInfo(admin,admin.getPassword(),"");
//    }
//}
